package edu.ciee.tz.dao;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.stereotype.Component;

import edu.ciee.tz.model.ZhunzaiEb;

@Component("zhunzaiebDao")
public class ZhunzaiEbDAO {

	public List<ZhunzaiEb> search(ZhunzaiEb z) throws Exception {

		String query = "where 1=1";

		if (z.getId() != 0) 
			query = query + " and id like '%" + z.getId() + "%'";// this.getID()
		if (z.getZhunzai_id()!= null&&z.getZhunzai_id().getId()!=0) 
			query = query + " and zhunzai_id like '%" + z.getZhunzai_id().getId() + "%'"; // this.getName()
		if (z.getEb_id()!=null) 
			query = query + " and eb_id like '%" + z.getEb_id() + "%'";// this.getID()
		if (z.getResult()!=null) 
			query = query + " and result like '%" + z.getResult()+ "%'";// this.getID()
		@SuppressWarnings("unchecked")
		List<ZhunzaiEb> zhunzai_list = hibernateTemplate.find("from ZhunzaiEb u "+ query);

		return zhunzai_list;
	}

	public void insert(ZhunzaiEb z) throws Exception {
		this.getHibernateTemplate().save(z);
	}

	public void delete(ZhunzaiEb z) throws Exception {
		this.getHibernateTemplate().delete(z);

	}

	public void update(ZhunzaiEb z) throws Exception {
		this.getHibernateTemplate().update(z);
	}

	private HibernateTemplate hibernateTemplate;

	public HibernateTemplate getHibernateTemplate() {
		return hibernateTemplate;
	}

	@Resource
	public void setHibernateTemplate(HibernateTemplate hibernateTemplate) {
		this.hibernateTemplate = hibernateTemplate;
	}
}
